package com.wb.mianxiangduixiang;

/**
 * @author 黄衡熙
 * @version 1.0
 * @date 2025年07月18日15:34
 */
public class Test11 {
    public static void main(String[] args) {
        System.out.println("********************对象所在的类被加载********************");
        System.out.println(Product.price);
        System.out.println("********************对象被创建********************");
        Product product = new Product();
        System.out.println(Product.price);
        System.out.println("**********************************");
        Product product2 = new Product("admin");
        System.out.println(product2.name);
        System.out.println("********************调用方法********************");
        product.getName();
        product.show();

    }
}

class Product {
    String name;
    static double price;


    public Product() {
        System.out.println("这是构造方法");
    }

    public Product(String name) {
        System.out.println("有参构造方法");
        this.name = name;
    }

    {
        System.out.println("代码块");
        name = "jack";
        price = 30.0;
    }

    static {
        System.out.println("静态代码块");
        // 静态代码块不能初始化实例属性
        // name = "jack";
        price = 20.0;
    }


    public void show() {
        System.out.println("这是show方法 name:" + name + ",price:" + price);
    }

    public void getName() {
        System.out.println("这是getName方法 name:" + name);
    }

    public static void print() {
        System.out.println("这是静态方法");
        System.out.println("price:" + price);
    }
}